import { createWebHistory, createRouter } from 'vue-router'
/* Layout */
import Layout from '@/layout'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('@/views/redirect/index.vue'),
            },
        ],
    },
    {
        path: '/login',
        component: () => import('@/views/login'),
        hidden: true,
    },
    // 报工手机端首页
    {
        path: '/todo',
        component: () => import('@/views/appTodo/index'),
        hidden: true,
    },
    // 取版
    {
        path: '/fetch',
        component: () => import('@/views/mobilePhone/fetch/index'),
        hidden: true,
    },
    // 补版
    {
        path: '/supplementary',
        component: () => import('@/views/mobilePhone/supplementary/index'),
        hidden: true,
    },
    // 取版列表
    {
        path: '/fetchList',
        component: () => import('@/views/mobilePhone/fetch/fetchList.vue'),
        hidden: true,
    },
    // 补版列表
    {
        path: '/supplementaryList',
        component: () => import('@/views/mobilePhone/supplementary/supplementaryList.vue'),
        hidden: true,
    },
    //裁切报工
    {
        path: '/cuttingReportApp',
        component: () => import('@/views/mobilePhone/cuttingReportApp'),
        hidden: true,
    },
    //覆膜报工
    {
        path: '/coverReportApp',
        component: () => import('@/views/mobilePhone/coverReportApp/index'),
        hidden: true,
    },
    //报工列表
    {
        path: '/reportList',
        component: () => import('@/views/mobilePhone/reportList.vue'),
        hidden: true,
    },
    //折页报工
    {
        path: '/foldingReport',
        component: () => import('@/views/mobilePhone/foldingReport/index'),
        hidden: true,
    },
    //印刷报工
    {
        path: '/printReportApp',
        component: () => import('@/views/mobilePhone/printReportApp'),
        hidden: true,
    },
    {
        path: '/register',
        component: () => import('@/views/register'),
        hidden: true,
    },
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/views/error/404'),
        hidden: true,
    },
    {
        path: '/401',
        component: () => import('@/views/error/401'),
        hidden: true,
    },
    {
        path: '',
        component: Layout,
        redirect: '/index',
        children: [
            {
                path: '/index',
                component: () => import('@/views/index'),
                name: 'Index',
                meta: { title: '首页', icon: 'dashboard', affix: true },
            },
        ],
    },
    {
        path: '/user',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'profile',
                component: () => import('@/views/system/user/profile/index'),
                name: 'Profile',
                meta: { title: '个人中心', icon: 'user' },
            },
        ],
    },
    {
        path: '/basicInfo',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'personnel/details',
                component: () => import('@/views/basicInfo/personnel/details'),
                name: 'personnelDetails',
                meta: { title: '人员信息' },
            },
            {
                path: 'workshop/details',
                component: () => import('@/views/basicInfo/workshop/details'),
                name: 'workshopDetails',
                meta: { title: '车间信息' },
            },
            {
                path: 'supplier/details',
                component: () => import('@/views/basicInfo/supplier/details'),
                name: 'supplierDetails',
                meta: { title: '供应商信息', icon: 'user' },
            },
            {
                path: 'workbench/details',
                component: () => import('@/views/basicInfo/workbench/details'),
                name: 'workbenchDetails',
                meta: { title: '设备/机台信息', icon: 'user' },
            },
            {
                path: 'customer/details',
                component: () => import('@/views/basicInfo/customer/details'),
                name: 'customerDetails',
                meta: { title: '客户信息', icon: 'user' },
            },
            {
                path: 'paperCoding/details',
                component: () => import('@/views/basicInfo/paperCoding/details'),
                name: 'paperCoding',
                meta: { title: '纸张编码信息', icon: 'user' },
            },
            {
                path: 'accessory/details',
                component: () => import('@/views/basicInfo/accessory/details'),
                name: 'accessory',
                meta: { title: '物料信息', icon: 'user' },
            },
            {
                path: 'paperProduction/details',
                component: () => import('@/views/basicInfo/paperProduction/details'),
                name: 'paperProduction',
                meta: { title: '生产纸张下单标准信息', icon: 'user' },
            },
        ],
    },

    {
        path: '/production',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'order/orderDetails',
                component: () => import('@/views/production/order/orderDetails'),
                name: 'orderInfoDetails',
                meta: { title: 'BOM清单详情' },
            },
            {
                path: 'cover/coverDetails',
                component: () => import('@/views/production/cover/coverDetails'),
                name: 'coverDetails',
                // name: 'coverInfoDetails',
                meta: { title: '封面生产' },
            },

            {
                path: 'text/textDetails',
                component: () => import('@/views/production/text/textDetails'),
                // name: 'textInfoDetails',
                name: 'textDetails',
                meta: { title: '内文生产' },
            },
            {
                path: 'allocation/allocationDetails',
                component: () => import('@/views/production/allocation/allocationDetails'),
                name: 'allocationInfoDetails',
                meta: { title: '生产单分配审核明细' },
            },
            {
                path: 'versionRoom/versionRoomDetail',
                component: () => import('@/views/production/versionRoom/versionRoomDetail'),
                name: 'versionRoomInfoDetail',
                meta: { title: '生产单内容审核' },
            },
            {
                path: 'makeVersion/versionDetails',
                component: () => import('@/views/production/makeVersion/versionDetails'),
                name: 'versionInfoDetails',
                meta: { title: '做版管理' },
            },
            {
                path: 'platemaking/platemakingDetails',
                component: () => import('@/views/production/platemaking/platemakingDetails'),
                name: 'platemakingInfoDetails',
                meta: { title: '制版管理' },
            },
            {
                path: 'takeVersion/takeVersionDetails',
                component: () => import('@/views/production/takeVersion/takeVersionDetails'),
                name: 'takeVersionInfoDetails',
                meta: { title: '取版管理' },
            },
            {
                path: 'printReport/printReportDetails',
                component: () => import('@/views/production/printReport/printReportDetails'),
                name: 'printReportInfoDetails',
                meta: { title: '印刷报工单详情' },
            },
            {
                path: 'foldingReport/foldReportDetails',
                component: () => import('@/views/production/foldingReport/foldReportDetails'),
                name: 'foldReportInfoDetails',
                meta: { title: '折页报工单' },
            },
            {
                path: 'otherReport/otherReportDetail',
                component: () => import('@/views/production/otherReport/otherReportDetail'),
                name: 'otherReportDetail',
                meta: { title: '其他报工管理' },
            },

            {
                path: 'invoice/invoiceDetails',
                component: () => import('@/views/production/invoice/invoiceDetails'),
                name: 'invoiceInfoDetails',
                meta: { title: '发货单管理' },
            },
            {
                path: 'cuttingReport/detail',
                component: () => import('@/views/production/cuttingReport/detail'),
                name: 'cuttingReportDetails',
                meta: { title: '裁切报工单' },
            },
            {
                path: 'bindReport/bindReportDetails',
                component: () => import('@/views/production/bindReport/bindReportDetails'),
                name: 'bindReportInfoDetails',
                meta: { title: '装订日报单详情' },
            },
            {
                path: 'coverReport/coverReportDetails',
                component: () => import('@/views/production/coverReport/coverReportDetails'),
                name: 'coverReportInfoDetails',
                meta: { title: '覆膜日报单' },
            },
            {
                path: 'supplementary/supplementaryDetails',
                component: () => import('@/views/production/supplementary/supplementaryDetails'),
                name: 'supplementaryInfoDetails',
                meta: { title: '补版管理明细' },
            },
            {
                path: 'quality/qualityDetails',
                component: () => import('@/views/production/quality/qualityDetails'),
                name: 'qualityInfoDetails',
                meta: { title: '质量管理详情' },
            },
            {
                path: 'waitTakeVersion/waitTakeDetails',
                component: () => import('@/views/production/waitTakeVersion/waitTakeDetails'),
                name: 'waitTakeInfoDetails',
                meta: { title: '待取版管理详情' },
            },
            {
                path: 'settlement/settlementDetails',
                component: () => import('@/views/production/settlement/settlementDetails'),
                name: 'settlementInfoDetails',
                meta: { title: '入库结算详情' },
            },
            {
                path: 'orderProgress/processPenetration',
                component: () => import('@/views/production/orderProgress/processPenetration'),
                name: 'processPenetrationInfo',
                meta: { title: '生产单机台分配详情' },
            },
            {
                path: 'orderProgress/quantityPenetration',
                component: () => import('@/views/production/orderProgress/quantityPenetration'),
                name: 'quantityPenetration',
                meta: { title: '发货明细' },
            },
            {
                path: 'searchMachineInventory/accessDetail',
                component: () => import('@/views/production/searchMachineInventory/accessDetail'),
                name: 'accessDetail',
                meta: { title: '领用明细' },
            },
            {
                path: 'searchMachineInventory/inventorySheetDetail',
                component: () => import('@/views/production/searchMachineInventory/inventorySheetDetail'),
                name: 'inventorySheetDetail',
                meta: { title: '盘点明细' },
            },
            {
                path: 'searchMachineInventory/cancellationDetail',
                component: () =>
                    import('@/views/production/searchMachineInventory/cancellationDetail'),
                name: 'cancellationDetail',
                meta: { title: '退库明细' },
            },
            {
                path: 'searchMachineInventory/reportDetail',
                component: () => import('@/views/production/searchMachineInventory/reportDetail'),
                name: 'reportDetail',
                meta: { title: '报工明细' },
            },
            {
                path: 'orderProgressfour/processPenetration',
                component: () => import('@/views/production/orderProgressfour/processPenetration'),
                name: 'processInfoPenetration',
                meta: { title: '明细' },
            },
        ],
    },
    {
        path: '/storage',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'warehouseReceipt/warehouseReceiptDetails',
                component: () => import('@/views/storage/warehouseReceipt/warehouseReceiptDetails'),
                name: 'receiptDetails',
                meta: { title: '入库单信息' },
            },
            {
                path: 'paperAccess/accessDetails',
                component: () => import('@/views/storage/paperAccess/accessDetails'),
                name: 'accessDetails',
                meta: { title: '领用单信息' },
            },
            {
                path: 'paperOutbound/outboundDetails',
                component: () => import('@/views/storage/paperOutbound/outboundDetails'),
                name: 'outboundDetails',
                meta: { title: '出库单信息' },
            },
            {
                path: 'transfer/transferDetails',
                component: () => import('@/views/storage/transfer/transferDetails'),
                name: 'transferInfoDetails',
                meta: { title: '调拨单信息' },
            },
            {
                path: 'cancellation/details',
                component: () => import('@/views/storage/cancellation/details'),
                name: 'cancellationDetails',
                meta: { title: '退库单信息' },
            },
            {
                path: 'inventorySheet/details',
                component: () => import('@/views/storage/inventorySheet/details'),
                name: 'inventorySheetDetails',
                meta: { title: '盘点单信息' },
            },
            {
                path: 'internalTransfer/details',
                component: () => import('@/views/storage/internalTransfer/details'),
                name: 'internalTransferDetails',
                meta: { title: '纸张内部调拨单信息' },
            },
        ],
    },
    {
        path: '/material',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'materialReceipt/details',
                component: () => import('@/views/material/materialReceipt/details'),
                name: 'materialReceiptDetails',
                meta: { title: '物料入库单信息' },
            },
            {
                path: 'materialRequisition/details',
                component: () => import('@/views/material/materialRequisition/details'),
                name: 'materialRequisitionDetails',
                meta: { title: '物料领用单信息' },
            },
            {
                path: 'returnSlip/details',
                component: () => import('@/views/material/returnSlip/details'),
                name: 'returnSlipDetails',
                meta: { title: '物料退库单信息' },
            },
            {
                path: 'returnNote/details',
                component: () => import('@/views/material/returnNote/details'),
                name: 'returnNoteDetails',
                meta: { title: '物料退货单信息' },
            },
            {
                path: 'MaterialInventorySheet/details',
                component: () => import('@/views/material/MaterialInventorySheet/details'),
                name: 'MaterialInventorySheetDetails',
                meta: { title: '物料盘点单信息' },
            },
        ],
    },
    //设备保养
    {
        path: '/maintenance',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'plan/details',
                component: () => import('@/views/maintenance/plan/details'),
                name: 'planDetails',
                meta: { title: '保养计划信息' },
            },
            {
                path: 'records/details',
                component: () => import('@/views/maintenance/records/details'),
                name: 'recordsDetails',
                meta: { title: '保养记录信息' },
            },
            {
                path: 'plan/planRecord',
                component: () => import('@/views/maintenance/plan/planRecord'),
                name: 'planRecord',
                meta: { title: '保养计划记录' },
            },
        ],
    },
    //废料
    {
        path: '/scrap',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'handle/details',
                component: () => import('@/views/scrap/handle/details'),
                name: 'handleDetails',
                meta: { title: '废料处理信息' },
            },
            {
                path: 'finalStatement/details',
                component: () => import('@/views/scrap/finalStatement/details'),
                name: 'finalStatementDetails',
                meta: { title: '废料结算单信息' },
            },
        ],
    },

    {
        path: '/repord',
        component: Layout,
        hidden: true,
        redirect: 'noredirect',
        children: [
            {
                path: 'persion/details',
                component: () => import('@/views/repord/persion/details'),
                name: 'Persiondetails',
                meta: { title: '工资列表明细', keepAlive: true },
            },
            {
                path: 'persion/printReportDetails',
                component: () => import('@/views/repord/persion/printReportDetails'),
                meta: { keepAlive: true },
                name: 'reportingdetails',
                meta: { title: '报工单明细' },
            },
        ],
    },
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
    {
        path: '/dataScreen',
        name: 'dataScreen',
        permissions: ['system:user:leader'],
        component: () => import('@/views/dataScreen/index'),
        meta: {
            title: '数据大屏',
            icon: 'dashboard',
        },
    },
    {
        path: '/system/user-auth',
        component: Layout,
        hidden: true,
        permissions: ['system:user:edit'],
        children: [
            {
                path: 'role/:userId(\\d+)',
                component: () => import('@/views/system/user/authRole'),
                name: 'AuthRole',
                meta: { title: '分配角色', activeMenu: '/system/user' },
            },
        ],
    },
    {
        path: '/system/role-auth',
        component: Layout,
        hidden: true,
        permissions: ['system:role:edit'],
        children: [
            {
                path: 'user/:roleId(\\d+)',
                component: () => import('@/views/system/role/authUser'),
                name: 'AuthUser',
                meta: { title: '分配用户', activeMenu: '/system/role' },
            },
        ],
    },
    {
        path: '/system/dict-data',
        component: Layout,
        hidden: true,
        permissions: ['system:dict:list'],
        children: [
            {
                path: 'index/:dictId(\\d+)',
                component: () => import('@/views/system/dict/data'),
                name: 'Data',
                meta: { title: '字典数据', activeMenu: '/system/dict' },
            },
        ],
    },
    {
        path: '/monitor/job-log',
        component: Layout,
        hidden: true,
        permissions: ['monitor:job:list'],
        children: [
            {
                path: 'index/:jobId(\\d+)',
                component: () => import('@/views/monitor/job/log'),
                name: 'JobLog',
                meta: { title: '调度日志', activeMenu: '/monitor/job' },
            },
        ],
    },
    {
        path: '/tool/gen-edit',
        component: Layout,
        hidden: true,
        permissions: ['tool:gen:edit'],
        children: [
            {
                path: 'index/:tableId(\\d+)',
                component: () => import('@/views/tool/gen/editTable'),
                name: 'GenEdit',
                meta: { title: '修改生成配置', activeMenu: '/tool/gen' },
            },
        ],
    },
]

const router = createRouter({
    history: createWebHistory(),
    routes: constantRoutes,
    scrollBehavior(to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { top: 0 }
        }
    },
})

export default router
